package com.aaa.hospital.ManagementEnd.controller;

import com.aaa.hospital.Client.pojo.Department;
import com.aaa.hospital.ManagementEnd.pojo.*;
import com.aaa.hospital.ManagementEnd.service.ExamineService;
import com.aaa.hospital.ManagementEnd.service.Impl.ExamineSerImpl;
import com.aaa.hospital.ManagementEnd.service.Impl.RegistrationServicesImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/examine")
public class ExamineController {
    //Autowired自动装配
    @Autowired
    private ExamineSerImpl examineSer;
    private RegistrationServicesImpl services;
    @RequestMapping(value = "/querAll",method = RequestMethod.GET)
    //ResponseBody将java对象转为json格式的数据
    @ResponseBody
    //查询
    public   List<User> selectAll( Integer appid){

        return examineSer.queryAll(appid);
    }
    @RequestMapping(name = "添加",value = "/add",method = RequestMethod.GET)
    @ResponseBody
    public String add(Examine examine,Integer visid){
        examineSer.insert(examine);
        if (examine.getAppid()!=null){
            return "true";
        }else {
            return "";
        }
    }
    //produces返回字符串编码
    @RequestMapping(name = "修改",value = "/update", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String update(Integer visid) {
        examineSer.update(visid);
        return JSON.toJSONString(true);
    }
    @RequestMapping(value = "/selectAll",method = RequestMethod.GET)
    // 将java对象转为json格式的数据
    @ResponseBody
    //查询信息
    public String selectAll(){
        JSONObject json = new JSONObject();
        List<Appointment> data = examineSer.selectAll();
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }
    @RequestMapping("/test")
    public String test( Model model,Integer appid){
        User user = examineSer.queryAll1(appid);
        VisitingCard visitingCard=examineSer.queryAll2(appid);
        visitingCard.setVisid(visitingCard.getVisid());
        user.setUname(user.getUname());
        user.setBirthday(user.getBirthday());
        user.setSex(user.getSex());
        user.setPhone(user.getPhone());
        model.addAttribute("user",user);
        model.addAttribute("visitingCard",visitingCard);
        return "ManagementEnd/Home/examine";
    }
    @RequestMapping("/res")
    @ResponseBody
    public   String selectAll1(HttpSession session){
        JSONObject json = new JSONObject();
        Integer a= (Integer) session.getAttribute("visid");
        List<RegistrationDB> data = examineSer.selectAll1(a);
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }
    @RequestMapping("/res1")
    @ResponseBody
    public   String selectAll2(String uname){
        JSONObject json = new JSONObject();
        List<RegistrationDB> data = examineSer.selectAll2(uname);
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }
}
